import time
import tkinter

from Attriabte import DTO
from View.WindowThread.InterfaceThread import InterfaceThread


class MoveAnimal(InterfaceThread):
    def __init__(self, win, widget:tkinter.Widget, config: DTO.MoveAnimalDto):
        self.win:tkinter.Tk = win
        self.config = config
        self.widget = widget

        if len(self.config.from_site ) == 0:
            self.from_x, self.from_y == widget.place_configure()['x'], widget.place_configure()['y']

        self.from_x, self.from_y = self.config.from_site

        self.target_x, self.target_y = self.config.to_site
        self.offset_x, self.offset_y = (
            self.target_x - self.from_x,
            self.target_y - self.target_x
        )

    def whileBody(self, count):
        x = self.offset_x / self.config.frame
        y = self.offset_y / self.config.frame

        self.widget.place(
            x=self.from_x + x * count,
            y=self.from_y + y * count
        )
        self.win.update()

        if count >= self.config.frame:
            return 'break:<threadManager>'

        time.sleep(self.config.speed)


